
data{
int<lower=0>N; //observations
int<lower=0>K; // covariates
int<lower=2>E;
int<lower=2, upper=E> ep[N];
matrix[N,K] x; // matrix of covariates
real y[N];
}

transformed data{
real zeros[K];
for(k in 1:K){
zeros[k]<-0.0; // this creates 0's to put in sigma's for betas
}
}

parameters {
vector[K] beta; //coefficients
vector[E] ranef_e; // 
vector<lower=0, upper=100>[K] sigma_beta; //sigmas for betas
real<lower=0, upper=100> sigma_e; //sigma for country
real<lower=0, upper=100> sigma_y; //sigma for 
}


transformed parameters {
vector[N] eta;
vector[N] y_hat;
eta<-x*beta;

for(n in 1:N){
y_hat[n]<-eta[n] + ranef_e[ep[n]] ;
}

}

model {
//priors
sigma_y ~ uniform(0,100);
beta ~ normal(zeros, sigma_beta);
sigma_e ~ cauchy(0,2.5);


//likelihood
y ~ normal(y_hat, sigma_y);
ranef_e ~ normal(0, sigma_e);
}

generated quantities{
real diff_expv_m1;
real controls;

controls<-beta[1]  + beta[3]*6.770396  + beta[4]*1 + beta[5]*3.764045  + beta[6]*.2319347 + beta[7]*.028781 + beta[8] + beta[19]; /// epgroup2, natparty 12;

diff_expv_m1<-(controls + beta[2]*.15743667)-(controls + beta[2]*.06039371);
}




